<?php
namespace Home\Controller;
use Think\Controller;
class ClassesController extends CommonController {
	//查找页面 精确
    public function index()
    {
        //公共显示变量
        $this->public_xianshi();

        //年级
        $grades = M('grade')->where(array('parent_id'=>0))->select();
        $this->assign('grades',$grades);
        //科目
        $kemus = M('subjects')->select();
        $this->assign('kemus',$kemus);

        //最新入住的老师
        $sql = "select t1.grades,t1.subject,t2.id,t2.city,t2.face,t2.create_time from showke_info as t1 inner join laoshi_user as t2 on t1.uid=t2.id where is_shenhe_xs=1 and is_dongjie=1 and is_del=0 order by create_time desc limit 4";
        $new_laoshi = M()->query($sql);
        $this->assign('new_laoshi',$new_laoshi);
        
        //-----------------------------------------------------------------

        //grade 高中
        $sql = "select * from grade where gradeid in(1,2,3,4)";
        $gz = M()->query($sql);
        $this->assign('gz',$gz);

        //grade 初中
        $sql = "select * from grade where gradeid in(5,6,7,8)";
        $cz = M()->query($sql);
        $this->assign('cz',$cz);

        //grade 小学
        $sql = "select * from grade where gradeid in(9,10,11,12,13,14,15,48,116)";
        $xx = M()->query($sql);
        $this->assign('xx',$xx);

		//获取年级选择的
		$grade_name = I('get.grade')?I('get.grade'):'';
		$this->assign('grade_name',$grade_name);


        //课程显示
        $kecheng = M('subjects')->select();
        $this->assign('kecheng',$kecheng);

        //获取课程科目选择的
        $subject_name = I('get.subject')?I('get.subject'):'';
        $this->assign('subject_name',$subject_name);

        //城市下区显示
        $city_info = I('get.newcity')?I('get.newcity'):'广州';
        //获取城市子id
        $cityid = M('city')->where(array('city_name'=>$city_info))->find();
        $citys = M('city')->where(array('parent_id'=>$cityid['cityid']))->select();
        $this->assign('citys',$citys);

        //获取选择的区域
        $area_name = I('get.area')?I('get.area'):'';
        $this->assign('area_name',$area_name);

        //获取价格排序
        $price = I('get.price')?I('get.price'):'';
        $this->assign('price',$price);
        //获取教龄排序
        $jiaoling = I('get.jiaoling')?I('get.jiaoling'):'';
        $this->assign('jiaoling',$jiaoling);

        //获取年级id
        $gradeid = M('grade')->where(array('grade_name'=>$grade_name))->getField('gradeid');

        //判断是否关键字搜索
        $keyword = I('post.keyword');
        if (!empty($keyword)) {
            //判断是否为数字   
            if (is_numeric($keyword )) {
                $sql = "select t1.id,t1.name,t1.face,t1.sfz_img,t1.jiaoshizheng_img,t1.qitazheng_img,t2.jiaoling,t2.jianjie,t2.laoshi_stye,t3.grades,t3.price,t3.subject,t3.address from laoshi_user as t1 inner join jiaoling_jli as t2 on t1.id=t2.uid inner join showke_info as t3 on t1.id=t3.uid where is_shenhe_xs=1 and is_dongjie=1 and is_del=0 and t1.city='{$city_info}' and t1.id='{$keyword}'";
            }else {
                $sql = "select t1.id,t1.name,t1.face,t1.sfz_img,t1.jiaoshizheng_img,t1.qitazheng_img,t2.jiaoling,t2.jianjie,t2.laoshi_stye,t3.grades,t3.price,t3.subject,t3.address from laoshi_user as t1 inner join jiaoling_jli as t2 on t1.id=t2.uid inner join showke_info as t3 on t1.id=t3.uid where is_shenhe_xs=1 and is_dongjie=1 and is_del=0 and t1.city='{$city_info}' and t1.name='{$keyword}'"; 
            }
        }else {
            $laoshi_user = M('laoshi_user');                  // 实例化question对象
            $count =    $laoshi_user->count();
            $Page       = new \Think\Page($count,20);// 实例化分页类 传入总记录数和每页显示的记录数(25)
            $show       = $Page->show();// 分页显示输出// 进行分页数据查询 

            if (!empty($price)) {
                //1
                if (!empty($grade_name) && empty($subject_name) && empty($area_name) && empty($price)) {
                    $sql = "select t1.id,t1.name,t1.face,t1.sfz_img,t1.jiaoshizheng_img,t1.qitazheng_img,t2.jiaoling,t2.jianjie,t2.laoshi_stye,t2.laoshi_stye,t3.grades,t3.price,t3.subject,t3.address from laoshi_user as t1 inner join jiaoling_jli as t2 on t1.id=t2.uid inner join showke_info as t3 on t1.id=t3.uid where is_shenhe_xs=1 and is_dongjie=1 and is_del=0 and t1.city='{$city_info}' and FIND_IN_SET('{$gradeid}',t3.grades) limit ".$Page->firstRow.','.$Page->listRows;
                }elseif (empty($grade_name) && !empty($subject_name) && empty($area_name) && empty($price)) {
                    $sql = "select t1.id,t1.name,t1.face,t1.sfz_img,t1.jiaoshizheng_img,t1.qitazheng_img,t2.jiaoling,t2.jianjie,t2.laoshi_stye,t3.grades,t3.price,t3.subject,t3.address from laoshi_user as t1 inner join jiaoling_jli as t2 on t1.id=t2.uid inner join showke_info as t3 on t1.id=t3.uid where is_shenhe_xs=1 and is_dongjie=1 and is_del=0 and t1.city='{$city_info}' and t3.subject='{$subject_name}' limit ".$Page->firstRow.','.$Page->listRows;
                }elseif (empty($grade_name) && empty($subject_name) && !empty($area_name) && empty($price)) {
                    $sql = "select t1.id,t1.name,t1.face,t1.sfz_img,t1.jiaoshizheng_img,t1.qitazheng_img,t2.jiaoling,t2.jianjie,t2.laoshi_stye,t3.grades,t3.price,t3.subject,t3.address from laoshi_user as t1 inner join jiaoling_jli as t2 on t1.id=t2.uid inner join showke_info as t3 on t1.id=t3.uid where is_shenhe_xs=1 and is_dongjie=1 and is_del=0 and t1.city='{$city_info}' and t3.sk_city='{$area_name}' limit ".$Page->firstRow.','.$Page->listRows;
                }elseif (empty($grade_name) && empty($subject_name) && empty($area_name) && !empty($price)) {
                    $sql = "select t1.id,t1.name,t1.face,t1.sfz_img,t1.jiaoshizheng_img,t1.qitazheng_img,t2.jiaoling,t2.jianjie,t2.laoshi_stye,t3.grades,t3.price,t3.subject,t3.address from laoshi_user as t1 inner join jiaoling_jli as t2 on t1.id=t2.uid inner join showke_info as t3 on t1.id=t3.uid where is_shenhe_xs=1 and is_dongjie=1 and is_del=0 and t1.city='{$city_info}' order by t3.price {$price} limit ".$Page->firstRow.','.$Page->listRows;
                }
                //2
                elseif (!empty($grade_name) && !empty($subject_name) && empty($area_name) && empty($price)) {
                    $sql = "select t1.id,t1.name,t1.face,t1.sfz_img,t1.jiaoshizheng_img,t1.qitazheng_img,t2.jiaoling,t2.jianjie,t2.laoshi_stye,t2.laoshi_stye,t3.grades,t3.price,t3.subject,t3.address from laoshi_user as t1 inner join jiaoling_jli as t2 on t1.id=t2.uid inner join showke_info as t3 on t1.id=t3.uid where is_shenhe_xs=1 and is_dongjie=1 and is_del=0 and t1.city='{$city_info}' and FIND_IN_SET('{$gradeid}',t3.grades) and t3.subject='{$subject_name}' limit ".$Page->firstRow.','.$Page->listRows;
                }elseif (!empty($grade_name) && empty($subject_name) && !empty($area_name) && empty($price)) {
                    $sql = "select t1.id,t1.name,t1.face,t1.sfz_img,t1.jiaoshizheng_img,t1.qitazheng_img,t2.jiaoling,t2.jianjie,t2.laoshi_stye,t2.laoshi_stye,t3.grades,t3.price,t3.subject,t3.address from laoshi_user as t1 inner join jiaoling_jli as t2 on t1.id=t2.uid inner join showke_info as t3 on t1.id=t3.uid where is_shenhe_xs=1 and is_dongjie=1 and is_del=0 and t1.city='{$city_info}' and FIND_IN_SET('{$gradeid}',t3.grades) and t3.sk_city='{$area_name}' limit ".$Page->firstRow.','.$Page->listRows;
                }elseif (!empty($grade_name) && empty($subject_name) && empty($area_name) && !empty($price)) {
                    $sql = "select t1.id,t1.name,t1.face,t1.sfz_img,t1.jiaoshizheng_img,t1.qitazheng_img,t2.jiaoling,t2.jianjie,t2.laoshi_stye,t2.laoshi_stye,t3.grades,t3.price,t3.subject,t3.address from laoshi_user as t1 inner join jiaoling_jli as t2 on t1.id=t2.uid inner join showke_info as t3 on t1.id=t3.uid where is_shenhe_xs=1 and is_dongjie=1 and is_del=0 and t1.city='{$city_info}' and FIND_IN_SET('{$gradeid}',t3.grades) order by t3.price {$price} limit ".$Page->firstRow.','.$Page->listRows;
                }elseif (empty($grade_name) && !empty($subject_name) && !empty($area_name) && empty($price)) {
                    $sql = "select t1.id,t1.name,t1.face,t1.sfz_img,t1.jiaoshizheng_img,t1.qitazheng_img,t2.jiaoling,t2.jianjie,t2.laoshi_stye,t2.laoshi_stye,t3.grades,t3.price,t3.subject,t3.address from laoshi_user as t1 inner join jiaoling_jli as t2 on t1.id=t2.uid inner join showke_info as t3 on t1.id=t3.uid where is_shenhe_xs=1 and is_dongjie=1 and is_del=0 and t1.city='{$city_info}' and t3.subject='{$subject_name}' and t3.sk_city='{$area_name}' limit ".$Page->firstRow.','.$Page->listRows;
                }elseif (empty($grade_name) && !empty($subject_name) && empty($area_name) && !empty($price)) {
                    $sql = "select t1.id,t1.name,t1.face,t1.sfz_img,t1.jiaoshizheng_img,t1.qitazheng_img,t2.jiaoling,t2.jianjie,t2.laoshi_stye,t2.laoshi_stye,t3.grades,t3.price,t3.subject,t3.address from laoshi_user as t1 inner join jiaoling_jli as t2 on t1.id=t2.uid inner join showke_info as t3 on t1.id=t3.uid where is_shenhe_xs=1 and is_dongjie=1 and is_del=0 and t1.city='{$city_info}' and t3.subject='{$subject_name}' order by t3.price {$price} limit ".$Page->firstRow.','.$Page->listRows;
                }elseif (empty($grade_name) && empty($subject_name) && !empty($area_name) && !empty($price)) {
                    $sql = "select t1.id,t1.name,t1.face,t1.sfz_img,t1.jiaoshizheng_img,t1.qitazheng_img,t2.jiaoling,t2.jianjie,t2.laoshi_stye,t2.laoshi_stye,t3.grades,t3.price,t3.subject,t3.address from laoshi_user as t1 inner join jiaoling_jli as t2 on t1.id=t2.uid inner join showke_info as t3 on t1.id=t3.uid where is_shenhe_xs=1 and is_dongjie=1 and is_del=0 and t1.city='{$city_info}' and t3.sk_city='{$area_name}' order by t3.price {$price} limit ".$Page->firstRow.','.$Page->listRows;
                }
                //3
                elseif (!empty($grade_name) && !empty($subject_name) && !empty($area_name) && empty($price)) {
                    $sql = "select t1.id,t1.name,t1.face,t1.sfz_img,t1.jiaoshizheng_img,t1.qitazheng_img,t2.jiaoling,t2.jianjie,t2.laoshi_stye,t3.grades,t3.price,t3.subject,t3.address from laoshi_user as t1 inner join jiaoling_jli as t2 on t1.id=t2.uid inner join showke_info as t3 on t1.id=t3.uid where is_shenhe_xs=1 and is_dongjie=1 and is_del=0 and t1.city='{$city_info}' and FIND_IN_SET('{$gradeid}',t3.grades) and t3.subject='{$subject_name}' and t3.sk_city='{$area_name}' limit ".$Page->firstRow.','.$Page->listRows;    
                }elseif (empty($grade_name) && !empty($subject_name) && !empty($area_name) && !empty($price)) {
                    $sql = "select t1.id,t1.name,t1.face,t1.sfz_img,t1.jiaoshizheng_img,t1.qitazheng_img,t2.jiaoling,t2.jianjie,t2.laoshi_stye,t3.grades,t3.price,t3.subject,t3.address from laoshi_user as t1 inner join jiaoling_jli as t2 on t1.id=t2.uid inner join showke_info as t3 on t1.id=t3.uid where is_shenhe_xs=1 and is_dongjie=1 and is_del=0 and t1.city='{$city_info}' and t3.subject='{$subject_name}' and t3.sk_city='{$area_name}' order by t3.price {$price} limit ".$Page->firstRow.','.$Page->listRows;  
                }elseif (!empty($grade_name) && empty($subject_name) && !empty($area_name) && !empty($price)) {
                    $sql = "select t1.id,t1.name,t1.face,t1.sfz_img,t1.jiaoshizheng_img,t1.qitazheng_img,t2.jiaoling,t2.jianjie,t2.laoshi_stye,t3.grades,t3.price,t3.subject,t3.address from laoshi_user as t1 inner join jiaoling_jli as t2 on t1.id=t2.uid inner join showke_info as t3 on t1.id=t3.uid where is_shenhe_xs=1 and is_dongjie=1 and is_del=0 and t1.city='{$city_info}' and FIND_IN_SET('{$gradeid}',t3.grades) and t3.sk_city='{$area_name}' order by t3.price {$price} limit ".$Page->firstRow.','.$Page->listRows;  
                }elseif (!empty($grade_name) && !empty($subject_name) && empty($area_name) && !empty($price)) {
                    $sql = "select t1.id,t1.name,t1.face,t1.sfz_img,t1.jiaoshizheng_img,t1.qitazheng_img,t2.jiaoling,t2.jianjie,t2.laoshi_stye,t3.grades,t3.price,t3.subject,t3.address from laoshi_user as t1 inner join jiaoling_jli as t2 on t1.id=t2.uid inner join showke_info as t3 on t1.id=t3.uid where is_shenhe_xs=1 and is_dongjie=1 and is_del=0 and t1.city='{$city_info}' and FIND_IN_SET('{$gradeid}',t3.grades) and t3.subject='{$subject_name}' order by t3.price {$price} limit ".$Page->firstRow.','.$Page->listRows;  
                }elseif (!empty($grade_name) && !empty($subject_name) && !empty($area_name) && !empty($price)) {
                    $sql = "select t1.id,t1.name,t1.face,t1.sfz_img,t1.jiaoshizheng_img,t1.qitazheng_img,t2.jiaoling,t2.jianjie,t2.laoshi_stye,t3.grades,t3.price,t3.subject,t3.address from laoshi_user as t1 inner join jiaoling_jli as t2 on t1.id=t2.uid inner join showke_info as t3 on t1.id=t3.uid where is_shenhe_xs=1 and is_dongjie=1 and is_del=0 and t1.city='{$city_info}' and FIND_IN_SET('{$gradeid}',t3.grades) and t3.subject='{$subject_name}' and t3.sk_city='{$area_name}' order by t3.price {$price} limit ".$Page->firstRow.','.$Page->listRows;  
                }else {
                    $sql = "select t1.id,t1.name,t1.face,t1.sfz_img,t1.jiaoshizheng_img,t1.qitazheng_img,t2.jiaoling,t2.jianjie,t2.laoshi_stye,t3.grades,t3.price,t3.subject,t3.address from laoshi_user as t1 inner join jiaoling_jli as t2 on t1.id=t2.uid inner join showke_info as t3 on t1.id=t3.uid where is_shenhe_xs=1 and is_dongjie=1 and is_del=0 and t1.city='{$city_info}' limit ".$Page->firstRow.','.$Page->listRows;
                }

            }elseif (!empty($jiaoling)) {
                //1
                if (!empty($grade_name) && empty($subject_name) && empty($area_name) && empty($jiaoling)) {
                    $sql = "select t1.id,t1.name,t1.face,t1.sfz_img,t1.jiaoshizheng_img,t1.qitazheng_img,t2.jiaoling,t2.jianjie,t2.laoshi_stye,t2.laoshi_stye,t3.grades,t3.price,t3.subject,t3.address from laoshi_user as t1 inner join jiaoling_jli as t2 on t1.id=t2.uid inner join showke_info as t3 on t1.id=t3.uid where is_shenhe_xs=1 and is_dongjie=1 and is_del=0 and t1.city='{$city_info}' and FIND_IN_SET('{$gradeid}',t3.grades) limit ".$Page->firstRow.','.$Page->listRows;
                }elseif (empty($grade_name) && !empty($subject_name) && empty($area_name) && empty($jiaoling)) {
                    $sql = "select t1.id,t1.name,t1.face,t1.sfz_img,t1.jiaoshizheng_img,t1.qitazheng_img,t2.jiaoling,t2.jianjie,t2.laoshi_stye,t3.grades,t3.price,t3.subject,t3.address from laoshi_user as t1 inner join jiaoling_jli as t2 on t1.id=t2.uid inner join showke_info as t3 on t1.id=t3.uid where is_shenhe_xs=1 and is_dongjie=1 and is_del=0 and t1.city='{$city_info}' and t3.subject='{$subject_name}' limit ".$Page->firstRow.','.$Page->listRows;
                }elseif (empty($grade_name) && empty($subject_name) && !empty($area_name) && empty($jiaoling)) {
                    $sql = "select t1.id,t1.name,t1.face,t1.sfz_img,t1.jiaoshizheng_img,t1.qitazheng_img,t2.jiaoling,t2.jianjie,t2.laoshi_stye,t3.grades,t3.price,t3.subject,t3.address from laoshi_user as t1 inner join jiaoling_jli as t2 on t1.id=t2.uid inner join showke_info as t3 on t1.id=t3.uid where is_shenhe_xs=1 and is_dongjie=1 and is_del=0 and t1.city='{$city_info}' and t3.sk_city='{$area_name}' limit ".$Page->firstRow.','.$Page->listRows;
                }elseif (empty($grade_name) && empty($subject_name) && empty($area_name) && !empty($jiaoling)) {
                    $sql = "select t1.id,t1.name,t1.face,t1.sfz_img,t1.jiaoshizheng_img,t1.qitazheng_img,t2.jiaoling,t2.jianjie,t2.laoshi_stye,t3.grades,t3.price,t3.subject,t3.address from laoshi_user as t1 inner join jiaoling_jli as t2 on t1.id=t2.uid inner join showke_info as t3 on t1.id=t3.uid where is_shenhe_xs=1 and is_dongjie=1 and is_del=0 and t1.city='{$city_info}' order by t2.jiaoling {$jiaoling} limit ".$Page->firstRow.','.$Page->listRows;
                }
                //2
                elseif (!empty($grade_name) && !empty($subject_name) && empty($area_name) && empty($jiaoling)) {
                    $sql = "select t1.id,t1.name,t1.face,t1.sfz_img,t1.jiaoshizheng_img,t1.qitazheng_img,t2.jiaoling,t2.jianjie,t2.laoshi_stye,t2.laoshi_stye,t3.grades,t3.price,t3.subject,t3.address from laoshi_user as t1 inner join jiaoling_jli as t2 on t1.id=t2.uid inner join showke_info as t3 on t1.id=t3.uid where is_shenhe_xs=1 and is_dongjie=1 and is_del=0 and t1.city='{$city_info}' and FIND_IN_SET('{$gradeid}',t3.grades) and t3.subject='{$subject_name}' limit ".$Page->firstRow.','.$Page->listRows;
                }elseif (!empty($grade_name) && empty($subject_name) && !empty($area_name) && empty($jiaoling)) {
                    $sql = "select t1.id,t1.name,t1.face,t1.sfz_img,t1.jiaoshizheng_img,t1.qitazheng_img,t2.jiaoling,t2.jianjie,t2.laoshi_stye,t2.laoshi_stye,t3.grades,t3.price,t3.subject,t3.address from laoshi_user as t1 inner join jiaoling_jli as t2 on t1.id=t2.uid inner join showke_info as t3 on t1.id=t3.uid where is_shenhe_xs=1 and is_dongjie=1 and is_del=0 and t1.city='{$city_info}' and FIND_IN_SET('{$gradeid}',t3.grades) and t3.sk_city='{$area_name}' limit ".$Page->firstRow.','.$Page->listRows;
                }elseif (!empty($grade_name) && empty($subject_name) && empty($area_name) && !empty($jiaoling)) {
                    $sql = "select t1.id,t1.name,t1.face,t1.sfz_img,t1.jiaoshizheng_img,t1.qitazheng_img,t2.jiaoling,t2.jianjie,t2.laoshi_stye,t2.laoshi_stye,t3.grades,t3.price,t3.subject,t3.address from laoshi_user as t1 inner join jiaoling_jli as t2 on t1.id=t2.uid inner join showke_info as t3 on t1.id=t3.uid where is_shenhe_xs=1 and is_dongjie=1 and is_del=0 and t1.city='{$city_info}' and FIND_IN_SET('{$gradeid}',t3.grades) order by t2.jiaoling {$jiaoling} limit ".$Page->firstRow.','.$Page->listRows;
                }elseif (empty($grade_name) && !empty($subject_name) && !empty($area_name) && empty($jiaoling)) {
                    $sql = "select t1.id,t1.name,t1.face,t1.sfz_img,t1.jiaoshizheng_img,t1.qitazheng_img,t2.jiaoling,t2.jianjie,t2.laoshi_stye,t2.laoshi_stye,t3.grades,t3.price,t3.subject,t3.address from laoshi_user as t1 inner join jiaoling_jli as t2 on t1.id=t2.uid inner join showke_info as t3 on t1.id=t3.uid where is_shenhe_xs=1 and is_dongjie=1 and is_del=0 and t1.city='{$city_info}' and t3.subject='{$subject_name}' and t3.sk_city='{$area_name}' limit ".$Page->firstRow.','.$Page->listRows;
                }elseif (empty($grade_name) && !empty($subject_name) && empty($area_name) && !empty($jiaoling)) {
                    $sql = "select t1.id,t1.name,t1.face,t1.sfz_img,t1.jiaoshizheng_img,t1.qitazheng_img,t2.jiaoling,t2.jianjie,t2.laoshi_stye,t2.laoshi_stye,t3.grades,t3.price,t3.subject,t3.address from laoshi_user as t1 inner join jiaoling_jli as t2 on t1.id=t2.uid inner join showke_info as t3 on t1.id=t3.uid where is_shenhe_xs=1 and is_dongjie=1 and is_del=0 and t1.city='{$city_info}' and t3.subject='{$subject_name}' order by t2.jiaoling {$jiaoling} limit ".$Page->firstRow.','.$Page->listRows;
                }elseif (empty($grade_name) && empty($subject_name) && !empty($area_name) && !empty($jiaoling)) {
                    $sql = "select t1.id,t1.name,t1.face,t1.sfz_img,t1.jiaoshizheng_img,t1.qitazheng_img,t2.jiaoling,t2.jianjie,t2.laoshi_stye,t2.laoshi_stye,t3.grades,t3.price,t3.subject,t3.address from laoshi_user as t1 inner join jiaoling_jli as t2 on t1.id=t2.uid inner join showke_info as t3 on t1.id=t3.uid where is_shenhe_xs=1 and is_dongjie=1 and is_del=0 and t1.city='{$city_info}' and t3.sk_city='{$area_name}' order by t2.jiaoling {$jiaoling} limit ".$Page->firstRow.','.$Page->listRows;
                }
                //3
                elseif (!empty($grade_name) && !empty($subject_name) && !empty($area_name) && empty($jiaoling)) {
                    $sql = "select t1.id,t1.name,t1.face,t1.sfz_img,t1.jiaoshizheng_img,t1.qitazheng_img,t2.jiaoling,t2.jianjie,t2.laoshi_stye,t3.grades,t3.price,t3.subject,t3.address from laoshi_user as t1 inner join jiaoling_jli as t2 on t1.id=t2.uid inner join showke_info as t3 on t1.id=t3.uid where is_shenhe_xs=1 and is_dongjie=1 and is_del=0 and t1.city='{$city_info}' and FIND_IN_SET('{$gradeid}',t3.grades) and t3.subject='{$subject_name}' and t3.sk_city='{$area_name}' limit ".$Page->firstRow.','.$Page->listRows;    
                }elseif (empty($grade_name) && !empty($subject_name) && !empty($area_name) && !empty($jiaoling)) {
                    $sql = "select t1.id,t1.name,t1.face,t1.sfz_img,t1.jiaoshizheng_img,t1.qitazheng_img,t2.jiaoling,t2.jianjie,t2.laoshi_stye,t3.grades,t3.price,t3.subject,t3.address from laoshi_user as t1 inner join jiaoling_jli as t2 on t1.id=t2.uid inner join showke_info as t3 on t1.id=t3.uid where is_shenhe_xs=1 and is_dongjie=1 and is_del=0 and t1.city='{$city_info}' and t3.subject='{$subject_name}' and t3.sk_city='{$area_name}' order by t2.jiaoling {$jiaoling} limit ".$Page->firstRow.','.$Page->listRows;  
                }elseif (!empty($grade_name) && empty($subject_name) && !empty($area_name) && !empty($jiaoling)) {
                    $sql = "select t1.id,t1.name,t1.face,t1.sfz_img,t1.jiaoshizheng_img,t1.qitazheng_img,t2.jiaoling,t2.jianjie,t2.laoshi_stye,t3.grades,t3.price,t3.subject,t3.address from laoshi_user as t1 inner join jiaoling_jli as t2 on t1.id=t2.uid inner join showke_info as t3 on t1.id=t3.uid where is_shenhe_xs=1 and is_dongjie=1 and is_del=0 and t1.city='{$city_info}' and FIND_IN_SET('{$gradeid}',t3.grades) and t3.sk_city='{$area_name}' order by t2.jiaoling {$jiaoling} limit ".$Page->firstRow.','.$Page->listRows;  
                }elseif (!empty($grade_name) && !empty($subject_name) && empty($area_name) && !empty($jiaoling)) {
                    $sql = "select t1.id,t1.name,t1.face,t1.sfz_img,t1.jiaoshizheng_img,t1.qitazheng_img,t2.jiaoling,t2.jianjie,t2.laoshi_stye,t3.grades,t3.price,t3.subject,t3.address from laoshi_user as t1 inner join jiaoling_jli as t2 on t1.id=t2.uid inner join showke_info as t3 on t1.id=t3.uid where is_shenhe_xs=1 and is_dongjie=1 and is_del=0 and t1.city='{$city_info}' and FIND_IN_SET('{$gradeid}',t3.grades) and t3.subject='{$subject_name}' order by t2.jiaoling {$jiaoling} limit ".$Page->firstRow.','.$Page->listRows;  
                }elseif (!empty($grade_name) && !empty($subject_name) && !empty($area_name) && !empty($jiaoling)) {
                    $sql = "select t1.id,t1.name,t1.face,t1.sfz_img,t1.jiaoshizheng_img,t1.qitazheng_img,t2.jiaoling,t2.jianjie,t2.laoshi_stye,t3.grades,t3.price,t3.subject,t3.address from laoshi_user as t1 inner join jiaoling_jli as t2 on t1.id=t2.uid inner join showke_info as t3 on t1.id=t3.uid where is_shenhe_xs=1 and is_dongjie=1 and is_del=0 and t1.city='{$city_info}' and FIND_IN_SET('{$gradeid}',t3.grades) and t3.subject='{$subject_name}' and t3.sk_city='{$area_name}' order by t2.jiaoling {$jiaoling} limit ".$Page->firstRow.','.$Page->listRows;  
                }else {
                    $sql = "select t1.id,t1.name,t1.face,t1.sfz_img,t1.jiaoshizheng_img,t1.qitazheng_img,t2.jiaoling,t2.jianjie,t2.laoshi_stye,t3.grades,t3.price,t3.subject,t3.address from laoshi_user as t1 inner join jiaoling_jli as t2 on t1.id=t2.uid inner join showke_info as t3 on t1.id=t3.uid where is_shenhe_xs=1 and is_dongjie=1 and is_del=0 and t1.city='{$city_info}' limit ".$Page->firstRow.','.$Page->listRows;
                }

            }else {
                if (!empty($grade_name) && empty($subject_name) && empty($area_name)) {
                    $sql = "select t1.id,t1.name,t1.face,t1.sfz_img,t1.jiaoshizheng_img,t1.qitazheng_img,t2.jiaoling,t2.jianjie,t2.laoshi_stye,t2.laoshi_stye,t3.grades,t3.price,t3.subject,t3.address from laoshi_user as t1 inner join jiaoling_jli as t2 on t1.id=t2.uid inner join showke_info as t3 on t1.id=t3.uid where is_shenhe_xs=1 and is_dongjie=1 and is_del=0 and t1.city='{$city_info}' and FIND_IN_SET('{$gradeid}',t3.grades) limit ".$Page->firstRow.','.$Page->listRows;
                }elseif (empty($grade_name) && !empty($subject_name) && empty($area_name)) {
                    $sql = "select t1.id,t1.name,t1.face,t1.sfz_img,t1.jiaoshizheng_img,t1.qitazheng_img,t2.jiaoling,t2.jianjie,t2.laoshi_stye,t3.grades,t3.price,t3.subject,t3.address from laoshi_user as t1 inner join jiaoling_jli as t2 on t1.id=t2.uid inner join showke_info as t3 on t1.id=t3.uid where is_shenhe_xs=1 and is_dongjie=1 and is_del=0 and t1.city='{$city_info}' and t3.subject='{$subject_name}' limit ".$Page->firstRow.','.$Page->listRows;
                }elseif (empty($grade_name) && empty($subject_name) && !empty($area_name)) {
                    $sql = "select t1.id,t1.name,t1.face,t1.sfz_img,t1.jiaoshizheng_img,t1.qitazheng_img,t2.jiaoling,t2.jianjie,t2.laoshi_stye,t3.grades,t3.price,t3.subject,t3.address from laoshi_user as t1 inner join jiaoling_jli as t2 on t1.id=t2.uid inner join showke_info as t3 on t1.id=t3.uid where is_shenhe_xs=1 and is_dongjie=1 and is_del=0 and t1.city='{$city_info}' and t3.sk_city='{$area_name}' limit ".$Page->firstRow.','.$Page->listRows;
                }elseif (!empty($grade_name) && !empty($subject_name) && empty($area_name)) {
                    $sql = "select t1.id,t1.name,t1.face,t1.sfz_img,t1.jiaoshizheng_img,t1.qitazheng_img,t2.jiaoling,t2.jianjie,t2.laoshi_stye,t3.grades,t3.price,t3.subject,t3.address from laoshi_user as t1 inner join jiaoling_jli as t2 on t1.id=t2.uid inner join showke_info as t3 on t1.id=t3.uid where is_shenhe_xs=1 and is_dongjie=1 and is_del=0 and t1.city='{$city_info}' and FIND_IN_SET('{$gradeid}',t3.grades) and t3.subject='{$subject_name}' limit ".$Page->firstRow.','.$Page->listRows;    
                }elseif (empty($grade_name) && !empty($subject_name) && !empty($area_name)) {
                    $sql = "select t1.id,t1.name,t1.face,t1.sfz_img,t1.jiaoshizheng_img,t1.qitazheng_img,t2.jiaoling,t2.jianjie,t2.laoshi_stye,t3.grades,t3.price,t3.subject,t3.address from laoshi_user as t1 inner join jiaoling_jli as t2 on t1.id=t2.uid inner join showke_info as t3 on t1.id=t3.uid where is_shenhe_xs=1 and is_dongjie=1 and is_del=0 and t1.city='{$city_info}' and t3.subject='{$subject_name}' and t3.sk_city='{$area_name}' limit ".$Page->firstRow.','.$Page->listRows;  
                }elseif (!empty($grade_name) && !empty($subject_name) && !empty($area_name)) {
                    $sql = "select t1.id,t1.name,t1.face,t1.sfz_img,t1.jiaoshizheng_img,t1.qitazheng_img,t2.jiaoling,t2.jianjie,t2.laoshi_stye,t3.grades,t3.price,t3.subject,t3.address from laoshi_user as t1 inner join jiaoling_jli as t2 on t1.id=t2.uid inner join showke_info as t3 on t1.id=t3.uid where is_shenhe_xs=1 and is_dongjie=1 and is_del=0 and t1.city='{$city_info}' and FIND_IN_SET('{$gradeid}',t3.grades) and t3.subject='{$subject_name}' and t3.sk_city='{$area_name}' limit ".$Page->firstRow.','.$Page->listRows;  
                }else {
                    $sql = "select t1.id,t1.name,t1.face,t1.sfz_img,t1.jiaoshizheng_img,t1.qitazheng_img,t2.jiaoling,t2.jianjie,t2.laoshi_stye,t3.grades,t3.price,t3.subject,t3.address from laoshi_user as t1 inner join jiaoling_jli as t2 on t1.id=t2.uid inner join showke_info as t3 on t1.id=t3.uid where is_shenhe_xs=1 and is_dongjie=1 and is_del=0 and t1.city='{$city_info}' limit ".$Page->firstRow.','.$Page->listRows;
                }
            }

        }
        //分页显示
        $chaxuns = M()->query($sql);
		$this->assign('chaxuns',$chaxuns);// 赋值数据集
		$this->assign('page',$show);// 赋值分页输出

		$this->assign('count',count($chaxuns));

        //授课年级 跟上面字段(1,2,3,4) 匹配对应ID跟name显示
        // $grade = M('grade')->where('parent_id=0')->select();
        // $this->assign('grade',$grade);


        $this->display();
    }
}